package cn.yotta.user.api.params.login;

import cn.yotta.common.utils.param.AssertUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.function.Supplier;

import static cn.yotta.user.api.error.CaptchaErrorCode.CAPTCHA_IS_BLANK;
import static cn.yotta.user.api.error.CaptchaErrorCode.CAPTCHA_TOKEN_IS_BLANK;
import static cn.yotta.user.api.error.PasswordErrorCode.PASSWORD_IS_EMPTY;

/**
 * @author wyaoyao
 * @date 2022/11/8 10:33
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@ToString(callSuper = true)
public abstract class BaseLoginByPasswordRequest extends BaseLoginRequest {

    @ApiModelProperty("图片验证码 token")
    private String captchaToken;

    @ApiModelProperty("图片验证码答案")
    private String captcha;

    @ApiModelProperty(value = "密码", required = true)
    private String password;

    @Override
    public void checkValid() {
        AssertUtil.notBlank(captcha, CAPTCHA_IS_BLANK.getCode());
        AssertUtil.notBlank(captchaToken, CAPTCHA_TOKEN_IS_BLANK.getCode());
        AssertUtil.notBlank(password, PASSWORD_IS_EMPTY.getCode());
    }

    @Override
    public Supplier<String> getCredentials() {
        return this::getPassword;
    }

}
